package com.igroupes.ovineherd.model.attribute.json;

import cn.hutool.json.JSONObject;
import com.igroupes.ovineherd.dto.response.Meta;
import com.igroupes.ovineherd.entity.DataModelAttributeEntity;
import com.igroupes.ovineherd.model.IParentModelData;
import com.igroupes.ovineherd.model.attribute.BasicAttribute;
import com.igroupes.ovineherd.model.dto.FieldApiResponse;
import com.igroupes.ovineherd.model.enums.FormKey;
import com.igroupes.ovineherd.model.enums.MySqlTypeKey;
import com.igroupes.ovineherd.query.FieldQuery;
import com.igroupes.ovineherd.query.ModelDataJsonAttributeQuery;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.List;

/**
 * json
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ToString(callSuper = true)
public class JsonModelData extends BasicAttribute{

    public JsonModelData() {
        super();
    }

    public Boolean verifyField(JsonModelData json) {
        return super.verifyField(json);
    }
    @Override
    public List<FieldQuery> sqlField(IParentModelData parentModelData, DataModelAttributeEntity dataModelAttributeEntityOld) {
        List<FieldQuery> fieldQueries = super.sqlField(parentModelData,dataModelAttributeEntityOld);
        FieldQuery fieldQuery = fieldQueries.get(0);
        fieldQuery.setType(MySqlTypeKey.LONGTEXT.getCode());
        fieldQueries.set(0,fieldQuery);
        return fieldQueries;
    }
    @Override
    public JSONObject getAttribute(ModelDataJsonAttributeQuery modelDataJsonAttributeQuery) {
        return super.getAttribute(modelDataJsonAttributeQuery);
    }
    @Override
    public List<FieldApiResponse> verifyRequestData(DataModelAttributeEntity modelAttributeEntity, Object value) {
        List<FieldApiResponse> fieldApiResponses = super.verifyRequestData(modelAttributeEntity, value);
        if(value == null){
            return fieldApiResponses;
        }
        return fieldApiResponses;
    }
    @Override
    public Meta getMeta(ModelDataJsonAttributeQuery dataModelAttributeEntity){
        return new Meta(FormKey.TEXT.getCode(), true, false, false);
    }
}